import os
import numpy as np
import pandas as pd
import os
import time
import glob
import re
import warnings
from program.pack.append_df_to_excel import append_df_to_excel
from pandas import to_datetime
from functools import reduce

warnings.filterwarnings("ignore")

# 列显示不全，进行设置
pd.set_option('display.max_columns', 500)
pd.set_option('display.unicode.ambiguous_as_wide', True)
pd.set_option('display.unicode.east_asian_width', True)
pd.set_option('display.width', 180)  # 设置打印宽度(**重要**)
path_execl = r'22.02.23_雷聪+训练\雷聪加训练集.xlsx'
path = r'\\172.18.5.225\data2\tai40D\TIANMA_TEST\TAI40-D\tianma-test8-rouxingping'

data_1 = pd.read_excel(path_execl)
# print(data_1)
# data_1 = data_1.head(2)
print(data_1)
j = 0
list_txt_new = pd.DataFrame()

for i in range(len(data_1)):
    file_name = path + '\\' + data_1.loc[i, '文件夹/表格名称'] + '\\' + 'label_dhq_ok_qx.txt'
    work_name = data_1.loc[i, '文件夹名称']
    print(file_name, work_name)
    file = open(file_name, "r")  # 读取txt
    list_txt = file.read().splitlines()  # 每一行数据写入到list中

    for k in list_txt:
        if work_name in k:
            word = file_name.replace('label_dhq_ok_qx.txt', '') + k
            list_txt_new.loc[j, '地址'] = word
            # list_txt_new.loc[j, 'txt'] = k

            j += 1

with open('label_dhq_ok_w.txt', 'w', encoding='utf-8') as f:
    list_txt_new.to_string(f)

#
# path_out = 'E:\work\suan_test\program-同事\远程办公_雷聪\雷聪标签重选.xlsx'
# append_df_to_excel(path_out, list_txt_new, sheet_name='重选', startcol=0,
#                    startrow=0, index=False)
# file_path_pic = data_1.loc[data_1['图片名'] == pic, '图片地址'].values[0]
